import tensorflow as tf
from sklearn import datasets
import matplotlib.pyplot as plt

if __name__ == '__main__':
    #  step 1 加载数据集
    iris = datasets.load_iris()
    # print(iris)
    features = iris.data
    labels = iris.target

    # 查看类型
    print(type (features))
    print(type (labels))

    # 查看维度
    print(features.ndim)
    print(labels.ndim)
    # 查看形状
    print(features.shape)
    print(labels.shape)
    # 查看数据类型
    print(features.dtype)
    print(labels.dtype)
    # 查看元素总个数
    print(features.size)
    print(labels.size)

    # 查看 features 的前 10 条数据
    print(features[0:10])
    print(labels[0:10])
    # 特征值名称 ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']
    print(iris.feature_names)
    # 鸢尾花的品种 ['setosa' 'versicolor' 'virginica']
    print(iris.target_names)

    #####################################################################
    plt.rcParams['font.sans-serif'] = ['SimHei']
    titles = iris.feature_names

    # print(features[:, 2])
    # print(set(labels))
    # plt.scatter(features[:,2], features[:,3], c=labels,cmap='brg', marker='*')
    # plt.xlabel(titles[2])
    # plt.ylabel(titles[3])
    # plt.title("鸢尾花数据集 花瓣长度、花瓣宽度与品种的关系图")

    # plt.savefig('petal.jpeg')

    plt.scatter(features[:, 0], features[:, 1], c=labels, cmap='brg', marker='*')
    plt.xlabel(titles[0])
    plt.ylabel(titles[1])
    plt.title("鸢尾花数据集 花萼长度、花萼宽度与品种的关系图")
    plt.savefig('sepal.jpeg')
    plt.show()


